<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>转工报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="factoryname + '转工报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'">
        <el-form-item label="主制分厂:" prop="factoryname">
          <el-select v-model="queryInfo.fromfactoryid" placeholder="请选择主制分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="承制分厂:">
          <el-input v-model="factoryname" :disabled="true"></el-input>
        </el-form-item>

        <el-form-item prop="productfamilyname" label="选择机型:">
          <el-select v-model="queryInfo.productfamilyname" placeholder="请选择机型" clearable filterable>
            <el-option v-for="p in productfamilyList" :key="p.productfamilyname" :label="p.productfamilyname"
              :value="p.productfamilyname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:300px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:300px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='rbcontainername' label="热表批次号:">
          <el-autocomplete v-model.trim="queryInfo.rbcontainername" placeholder="请输入热表批次号" :trigger-on-focus="false"
            style="width:300px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop="receivedate" label="接收日期:">
          <el-date-picker v-model="queryInfo.receivedate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item prop="needcompletedate" label="要求完成时间:">
          <el-date-picker v-model="queryInfo.needcompletedate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item prop="receivepersonid" label="接收人:">
          <el-select v-model="queryInfo.receivepersonid" placeholder="请选择" clearable filterable style="width:120px;">
            <el-option v-for="p in diaoDuYuanList" :key="p.employeeid" :label="p.fullname" :value="p.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='specno' label="工序号:">
          <el-input v-model.trim="queryInfo.specno" placeholder="请输入工序号" clearable style="width:140px;"></el-input>
        </el-form-item>

        <el-form-item prop="status" label="转工状态:">
          <el-select v-model="queryInfo.status" placeholder="请选择" clearable filterable style="width:120px;">
            <el-option v-for="s in statusList" :key="s.status" :label="s.status" :value="s.status">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop="status" label="是否已入库:">
          <el-select v-model="queryInfo.isinstore" placeholder="请选择" style="width:140px;">
            <el-option :key="'未入库'" :label="'未入库'" :value="'未入库'"></el-option>
            <el-option :key="'已入库'" :label="'已入库'" :value="'已入库'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop="isdispatch" label="热表是否已派工">
          <el-select v-model="queryInfo.isdispatch" clearable filterable placeholder="请选择" style="width:140px;">
            <el-option :key="'已派工'" :label="'已派工'" :value="'已派工'"></el-option>
            <el-option :key="'未派工'" :label="'未派工'" :value="'未派工'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="主制分厂" prop="fromfactory" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="承制分厂" prop="tofactory" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="机型" prop="familylistnames" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件图号" prop="productname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="流水卡号" prop="containername" width="180" show-overflow-tooltip></el-table-column>
        <el-table-column label="热表批次号" prop="rbcontainername" width="250" show-overflow-tooltip></el-table-column>
        <el-table-column label="转出工序" prop="workflowstepname" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="转出数量" prop="qty" width="80"></el-table-column>
        <el-table-column label="转出时间" prop="senddate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="要求完成时间" prop="needcompletedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="接收时间" prop="toacceptdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="接收人" width="80">
          <template slot-scope="scope" v-if="scope.row.fullname">
            <el-tag>{{scope.row.fullname}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="完成时间" prop="completedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="转入时间" prop="recivedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="转入工序" prop="inspec" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="预计完成时间" prop="estimatedcompletedate" width="100" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="转入数量" prop="acceptanceqty" width="80"></el-table-column>
        <el-table-column label="转工状态" width="80">
          <template slot-scope="scope">
            <div v-if="scope.row.status === '未接收'">
              <el-tag type="info">未接收</el-tag>
            </div>
            <div v-else-if="scope.row.status === '待完成'">
              <el-tag>待完成</el-tag>
            </div>
            <div v-else-if="scope.row.status === '已完成'">
              <el-tag type="success">已完成</el-tag>
            </div>
            <div v-else="scope.row.status === '转工拒收'">
              <el-tag type="danger">转工拒收</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="热表是否派工" width="80">
          <template slot-scope="scope">
            <el-tag :type="scope.row.dispatchstatus === '已派工'?'success':'danger'">{{scope.row.dispatchstatus}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="拒收时间" prop="denydate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="超期时间" width="80">
          <template slot-scope="scope" v-if="scope.row.delay !== null">
            {{scope.row.delay + '天'}}
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[12,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getProductFamily, getFactoryUsersByRoleName, getFactory, getFactoryInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js';
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        queryInfo: {
          tofactoryid: '',//承制分厂
          fromfactoryid: '',//发出分厂
          productfamilyname: '',//机型
          productname: '',//零件图号
          receiver: '',//接收人(调度员)
          receivedate: '',//接收日期
          needcompletedate: '',
          containername: '',//流水卡号
          rbcontainername: '',//热表批次号
          specno: '',// 工序号
          status: '',//转工状态
          isinstore: '未入库',//是否已入库
          isdispatch: '',//热表是否已派工
          currentPage: 1,//当前页
          pageSize: 12//每页显示条数
        },
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        factoryname: '',
        factoryList: [],//发出分厂
        productfamilyList: [],//机型
        diaoDuYuanList: [],//接收人(调度员)
        statusList: [
          { status: '全部' },
          { status: '未接收' },
          { status: '待完成' },
          { status: '已完成' },
          { status: '转工拒收' }
        ],
        dataList: [],
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] },
        baseApi: '../handler/report/RbContainerShipRecord.ashx',
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback })
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback })
        },
        //查询数据
        async getData(currentpage) {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post(`${this.baseApi}?action=getData`, {
            type: 'getData',
            ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
        },
        //导出excel
        async getExportExcel() {
          const config = {
            url: `${this.baseApi}?action=exportExcel`,
            data: { type: 'exportExcel', ...this.queryInfo, factoryname: this.factoryname }
          }
          exportExcelData(config, this);
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        const factoryid = Decrypt(getParams('factoryid'));
        this.productfamilyList = await getProductFamily();
        this.factoryList = await getFactory();
        const factoryInfo = await getFactoryInfo({ factoryid });
        const { factoryname } = factoryInfo[0];
        this.queryInfo.tofactoryid = factoryInfo[0].factoryid;
        this.factoryname = factoryname;
        document.title = factoryname + '转工报表';
        this.diaoDuYuanList = await getFactoryUsersByRoleName({ factoryid, rolename: '调度员' });
      },
      watch: {
        queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true }
      }
    })
  </script>
</body>

</html>